<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        span {
            display: inline-block;
            width: 40px;
            line-height: 40px;
            background: #333;
            text-align: center;
            color: white;
            font-size: 18px;
            font-weight: bold;
        }
    </style>
    <script>
        window.addEventListener('load', function() {
            // 1. 获取元素（时分秒盒子） 
            var hour = document.querySelector('.hour'); // 小时的黑色盒子
            var minute = document.querySelector('.minute'); // 分钟的黑色盒子
            var second = document.querySelector('.second'); // 秒数的黑色盒子
            var inputTime = new Date('2021-4-6 15:00:00'); // 返回的是用户输入时间总的毫秒数

            timer()
                // 2. 开启定时器
            setInterval(timer, 1000);

            function timer() {
                const nowTime = new Date()
                const times = (inputTime - nowTime) / 1000
                    // console.log(times);
                let h = window.parseInt(times / 60 / 60)
                h = h < 10 ? '0' + h : h
                hour.innerHTML = h
                let m = window.parseInt(times / 60 % 60)
                m = m < 10 ? '0' + m : m
                minute.innerHTML = m
                let s = window.parseInt(times % 60)
                s = s < 10 ? '0' + s : s
                second.innerHTML = s
            }
        })
    </script>
</head>

<body>
    <div>
        <span class="hour"></span>
        <span class="minute"></span>
        <span class="second"></span>
    </div>
</body>

</html>